package cn.modoumama.common.tools.cipher;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @Description TODO 类描述信息
 * @Author dengqiang
 * @Date 2019/1/8 16:50
 * @Version 1.0
 **/
@SuppressWarnings("restriction")
public class Base64Utils{
	private static BASE64Encoder BASE64_ENCODER = new BASE64Encoder();
    private static BASE64Decoder BASE64_DECODER = new BASE64Decoder();

    private Base64Utils() {
        super();
    }

    public static void encode(InputStream inputStream, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encode(inputStream, outputStream);
    }

    
    public static void encode(byte[] bytes, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encode(bytes, outputStream);
    }

    
    public static String encode(byte[] bytes) {
        return BASE64_ENCODER.encode(bytes);
    }

    
    public static void encode(ByteBuffer byteBuffer, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encode(byteBuffer, outputStream);
    }

    
    public static String encode(ByteBuffer byteBuffer) {
        return BASE64_ENCODER.encode(byteBuffer);
    }

    
    public static void encodeBuffer(InputStream inputStream, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encodeBuffer(inputStream, outputStream);
    }

    
    public static void encodeBuffer(byte[] bytes, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encodeBuffer(bytes, outputStream);
    }

    
    public static String encodeBuffer(byte[] bytes) {
        return BASE64_ENCODER.encodeBuffer(bytes);
    }

    
    public static void encodeBuffer(ByteBuffer byteBuffer, OutputStream outputStream) throws IOException {
        BASE64_ENCODER.encodeBuffer(byteBuffer, outputStream);
    }

    
    public static String encodeBuffer(ByteBuffer byteBuffer) {
        return BASE64_ENCODER.encodeBuffer(byteBuffer);
    }

    
    public static void decodeBuffer(InputStream inputStream, OutputStream outputStream) throws IOException {
        BASE64_DECODER.decodeBuffer(inputStream, outputStream);
    }

    
    public static byte[] decodeBuffer(String s) throws IOException {
        return BASE64_DECODER.decodeBuffer(s);
    }

    
    public static byte[] decodeBuffer(InputStream inputStream) throws IOException {
        return BASE64_DECODER.decodeBuffer(inputStream);
    }

    
    public static ByteBuffer decodeBufferToByteBuffer(String s) throws IOException {
        return BASE64_DECODER.decodeBufferToByteBuffer(s);
    }

    
    public static ByteBuffer decodeBufferToByteBuffer(InputStream inputStream) throws IOException {
        return BASE64_DECODER.decodeBufferToByteBuffer(inputStream);
    }
}
